package com.meanbean.studytime.controls;

import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 * This can be used to see the result of the user's choice when asked a question.
 * @author Derek Webb
 */
public class DialogResult extends Stage
{
	@FXML private Label messageLabel;
	
	public enum Result { Yes, No, Cancel };
	private Result result = Result.Cancel;
	
	/**
	 * Creates a DialogResult object.
	 * @param title The title of the dialog window.
	 * @param message The message to display on the dialog.
	 */
	public DialogResult(String title, String message)
	{
		super(StageStyle.UTILITY);
		
		initModality(Modality.WINDOW_MODAL);
		
		try
		{
			FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("DialogResult.fxml"));
			fxmlLoader.setController(this);
			
			Parent root = (Parent)fxmlLoader.load();
			
			setTitle(title);
			messageLabel.setText(message);
		
			setScene(new Scene(root));
		
			sizeToScene();
		}
		catch (Exception e)
		{
			e.printStackTrace();
			
			// TODO: Add log entry here
		}
	}
	
	/**
	 * @return The result from the dialog (the user's selection).
	 */
	public Result getResult()
	{
		return result;
	}
	
	/**
	 * Called if the user clicked the 'Yes' button.
	 * Sets the result to 'Yes' and closes the dialog.
	 */
	@FXML
	private void yesClicked()
	{
		result = Result.Yes;
		close();
	}
	
	/**
	 * Called if the user clicked the 'No' button.
	 * * Sets the result to 'No' and closes the dialog.
	 */
	@FXML
	private void noClicked()
	{
		result = Result.No;
		close();
	}
	
	/**
	 * Called if the user clicked the 'Cancel' button.
	 * * Sets the result to 'Cancel' and closes the dialog.
	 */
	@FXML
	private void cancelClicked()
	{
		result = Result.Cancel;
		close();
	}
	
	/**
	 * Closes the dialog.
	 */
	@FXML
	public void exit()
	{
		close();
	}
}
